<template>
  <div class="app-container">
    <el-alert
      type="info"
      :title="content"
      style="margin-bottom: 20px;"
    >
    </el-alert>
    <el-form :inline="true" label-width="80px">
      <el-form-item label="渠道">
        <el-select  v-model="queryParams.source" placeholder="不限" clearable size="small">
          <el-option
            v-for="dict in sourceOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="下级">
        <el-select  v-model="queryParams.level" placeholder="不限" clearable size="small">
          <el-option
            v-for="dict in levelOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="postList">
      <el-table-column label="用户编号" align="center" prop="idNo"/>
      <el-table-column label="订单编号" align="center" prop="payno"/>
      <el-table-column label="头像" align="center" prop="path">
        <template slot-scope="scope">
          <div>
            <el-popover placement="right" title="" trigger="click">
              <img :src="scope.row.path" alt="">
              <img slot="reference" :src="scope.row.path" alt="" style="max-height: 50px;max-width: 50px">
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="nickname"/>
      <el-table-column label="真实姓名" align="center">
        <template slot-scope="scope">
          <span :class="scope.row.realname?'':'text-warning'">{{ scope.row.realname?scope.row.realname:'未实名' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="mobile"/>
      <el-table-column label="购买数量" align="center" prop="number"/>
      <el-table-column label="支付金额" align="center" prop="totalamount">
        <template slot-scope="scope">
          <span>{{formatCurrency(scope.row.totalamount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="购买时间" align="center">
        <template slot-scope="scope">
          <span>{{ dateFormat(scope.row.createtime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付状态" align="center" prop="status" :formatter="payFormat">
        <template slot-scope="scope">
          <span v-if="scope.row.status===0" class="text-warning">{{ payFormat(scope.row) }}</span>
          <span v-else-if="scope.row.status===9" >{{ payFormat(scope.row) }}</span>
          <span v-else class="text-info">线下支付</span>
        </template>
      </el-table-column>
      <el-table-column label="购买源" align="center" prop="source" :formatter="sourceFormat"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import {carBuyViewList} from "@/api/maker/buy";

  export default {
    data() {
      return {
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        // 是否显示弹出层
        // 状态数据字典
        sourceOptions: [],
        payOptions:[],
        levelOptions:[{dictValue:1,dictLabel:'一级'},{dictValue:2,dictLabel:'二级'}],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId:undefined,
          level:undefined,
          source:undefined
        }
      };
    },
    created() {
      this.getDicts("yy_pay_status").then(response => {
        this.payOptions = response.data;
      });
      this.getDicts("yy_maker_source").then(response => {
        this.sourceOptions = response.data;
      });
      this.queryParams.userId = this.$route.params && this.$route.params.userId;
      this.content = '用户昵称为:' + this.$route.params.nickname + ",手机号为:" + this.$route.params.mobile + "的创客下级购买记录";


      this.getList();
    },
    methods: {
      sourceFormat(row, column) {
        return this.selectDictLabel(this.sourceOptions, row.source);
      },
      payFormat(row, column) {
        return this.selectDictLabel(this.payOptions, row.status);
      },
      getList() {
        carBuyViewList(this.queryParams).then(response => {
          this.postList = response.rows;
          console.log(this.postList);
          this.total = response.total;
          this.loading = false;
        });
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      }
    }
  }
</script>

<style scoped>

</style>
